use dataset_county, clear

sort fips year

gen myline = 50

foreach y in 1964 1972 1976 1984 1992 2000 2008 2016 {

	di `y'
	
	if `y' == 1964 | `y' == 1976 | `y' == 1992 | `y' == 2008 local flip fliprepdem 
	if `y' == 1972 | `y' == 1984 | `y' == 2000 | `y' == 2016 local flip flipdemrep

	egen flipm = mean(`flip') if year == `y', by(fips)
	egen flip = mean(flipm), by(fips)

	#delimit;

	xtline demvoteshare if flip == 1
	, 
		t(year) i(fips) overlay
		legend(off)
		title(`y', size(huge))
		xlab(1952(8)2016, angle(45) labsize(vlarge))
		ylab(0(20)100, angle(horiz) labsize(vlarge))
		plotregion(style(none))
		xtitle("")
		ytitle("")
		xline(`y', lwid(medthick) lpat(dash) lcol(black))
		addplot(scatteri 50 1952 50 2016, recast(line) col(black)
			lpat(solid) lpat(dash) lwid(medthick))
			;
			
	#delimit cr

	drop flip flipm
	
	gr export "figure 4 `y'.pdf", replace
	
	serset clear

}
